#include <bits/stdc++.h>

#define LL long long

const int kN = 5e5 + 10;
int n;
int S[kN], A[kN], B[kN];
int fail[kN], fa[kN], vis[kN];

void solve() {
    LL ans = 0, sumb = 0;
    fail[1] = 0;
    for (int i = 1, j = 0; i <= n; ++i) {
        std::cin >> S[i] >> A[i] >> B[i];
        S[i] = (1ll * ans + S[i]) % n;
        if (i > 1) {
            fa[i - 1] = S[fail[i - 1] + 1] == S[i] ? fa[fail[i - 1]] : fail[i - 1];
            while (j && S[i] != S[j + 1]) j = fail[j];
            if (S[j + 1] == S[i]) ++j;
            fail[i] = j;
        }

        if (S[i] == S[1]) sumb += B[i];
        int p = i - 1;
        while (p) {
            int q = fa[p];
            if (S[p + 1] != S[i]) {
                while (p != q) sumb -= B[i - p], p = fail[p];
            }
            p = q;
        }
        ans += 1ll * sumb * A[i];

        std::cout << ans << "\n";
    }
}

int main() {
    // freopen("1.txt", "r", stdin);
    std::ios::sync_with_stdio(0);
    std::cin.tie(0), std::cout.tie(0);
    std::cin >> n;
    solve();
    return 0;
}